package com.vehicle_information_management_system.controller;

import com.vehicle_information_management_system.utils.Result;
import org.springframework.ai.client.AiClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AIController {

    private final AiClient aiClient;


    public AIController(AiClient aiClient) {
        this.aiClient = aiClient;
    }

    @GetMapping("/chat")
    public Result<?> chat(
            @RequestParam(value = "message",defaultValue = "Hi") String message
    ){
        try{
            return Result.success(aiClient.generate(message));
        }catch (Exception e) {
            return Result.error(400, e.getMessage());
        }

    }

}
